<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
    <link rel="stylesheet" href="style.css" type="text/css" />

    <style type="text/css">
        #map {
            width: 800px;
            height: 600px;
            border: 1px solid black;
        }
        .olPopup p { margin:0px; font-size: .9em;}
        .olPopup h2 { font-size:1.2em; }
    </style>
    <script src="http://xepec.ru/openl/openlayers/lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var lon = 4187888;
        var lat = 7509599;
        var zoom = 10;
        var map, select;

        function init(){


 map = new OpenLayers.Map('map',
              {'maxResolution': 360/512/16,
               'numZoomLevels':15,
                controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.ScaleLine() ]});
//            map = new OpenLayers.Map( 'map' );
        map.addControl(new OpenLayers.Control.Permalink());

        var wms = new OpenLayers.Layer.WMS( "WMS",

/*
change here to suite your setup
*/
                "http://xepec.ru/mapserver?",
                {map: 'osm/osm.map',


        layers: 'default',
        format: 'aggpng24',
//      format: 'svg',
        transparent: 'off'},
                {maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
                scales: [5000,10000,25000,50000,100000,250000,500000,
                         1000000,2500000,5000000,10000000,25000000,50000000,100000000],
                units: 'm',
                projection:new OpenLayers.Projection("EPSG:900913"),
                gutter:0,
                ratio:1,
                wrapDateLine: true,
                isBaselayer:true,
                singleTile:true,//одноэлементная загрузка
                transitionEffect:'resize'} );
//var vector = new OpenLayers.Layer.Vector("Editable Vectors");

//            map.addLayers([wms]);



////////////////////////////////////////////////////


            var sundials = new OpenLayers.Layer.Vector("KML", {
                projection: new OpenLayers.Projection("EPSG:900913"),//map.displayProjection,
                strategies: [new OpenLayers.Strategy.Fixed()],
                protocol: new OpenLayers.Protocol.HTTP({
                    url: "./sundials.kml",
                    format: new OpenLayers.Format.KML({
                        extractStyles: true,
                        extractAttributes: true
                    })
                })
            });
            
            map.addLayers([wms, sundials]);
            
            select = new OpenLayers.Control.SelectFeature(sundials);
            
            sundials.events.on({
                "featureselected": onFeatureSelect,
                "featureunselected": onFeatureUnselect
            });

          map.addControl(select);
        select.activate();   
//      //      map.zoomToExtent(new OpenLayers.Bounds(68.774414,11.381836,123.662109,34.628906));


            if(!map.getCenter())
                map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
            map.addControl(new OpenLayers.Control.Permalink('permalink'));
            map.addControl(new OpenLayers.Control.MousePosition());

        }
        function onPopupClose(evt) {
            select.unselectAll();
        }
        function onFeatureSelect(event) {
            var feature = event.feature;
            // Since KML is user-generated, do naive protection against
            // Javascript.
            var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
            if (content.search("<script") != -1) {
                content = "Content contained Javascript! Escaped content below.<br />" + content.replace(/</g, "&lt;");
            }
            popup = new OpenLayers.Popup.FramedCloud("chicken", 
                                     feature.geometry.getBounds().getCenterLonLat(),
                                     new OpenLayers.Size(100,100),
                                     content,
                                     null, true, onPopupClose);
            feature.popup = popup;
            map.addPopup(popup);
        }
        function onFeatureUnselect(event) {
            var feature = event.feature;
            if(feature.popup) {
                map.removePopup(feature.popup);
                feature.popup.destroy();
                delete feature.popup;
            }


        }
    </script>
  </head>
  <body onload="init()">
      <div id="map" class="smallmap"></div>
  </body>
</html>
